﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.sim {
    import flash.events.*;
    import flash.utils.*;
    import Classes.*;
    import Display.*;

    public class StadiumManager {

        public static var TIME_SHOWN:int;
        public static var TIME_BETWEEN_DIALOGS:int;
        public static var NUMBER_OF_PLAYS:int;

        private var m_result:Object;
        private var m_open:Timer;
        private var m_close:Timer;
        private var m_stadium:Stadium;
        private var m_dialog:StadiumReplayDialog;
        private var m_playCounter:int = 0;

        public function StadiumManager(_arg1:Object, _arg2:Stadium){
            this.m_result = _arg1;
            this.m_stadium = _arg2;
            this.m_stadium.playing = true;
            TIME_SHOWN = Global.gameSettings.getAttribute("stadiumReplayDisplayTime");
            TIME_BETWEEN_DIALOGS = Global.gameSettings.getAttribute("stadiumTimeBetweenReplays");
            NUMBER_OF_PLAYS = Global.gameSettings.getAttribute("stadiumNumberOfPlays");
            this.m_open = new Timer(TIME_SHOWN);
            this.m_open.addEventListener(TimerEvent.TIMER, this.onOpen);
            this.m_close = new Timer(TIME_BETWEEN_DIALOGS);
            this.m_close.addEventListener(TimerEvent.TIMER, this.onClose);
            this.m_dialog = new StadiumReplayDialog(this.m_stadium, false);
            this.m_dialog.yOffset = -125;
            UI.displayPopup(this.m_dialog);
            this.m_dialog.hide();
            this.m_open.start();
        }
        private function onOpen(_arg1:TimerEvent):void{
            this.m_open.stop();
            this.m_close.start();
            var _local2:String = this.m_result.replay[this.m_playCounter].attacker;
            var _local3:String = this.m_result.replay[this.m_playCounter].defender;
            var _local4:String = this.m_result.replay[this.m_playCounter].attackerScore;
            var _local5:String = this.m_result.replay[this.m_playCounter].defenderScore;
            var _local6:String = ZLoc.t("Main", this.m_result.replay[this.m_playCounter].description, {
                name:ZLoc.tn(_local2),
                defender:ZLoc.tn(_local3)
            });
            this.m_dialog.setText(_local6);
            this.m_dialog.show();
        }
        private function onClose(_arg1:TimerEvent):void{
            this.m_close.stop();
            this.m_open.start();
            this.m_dialog.hide();
            this.m_playCounter++;
            if (this.m_playCounter >= NUMBER_OF_PLAYS){
                this.onEnd();
            };
        }
        private function onEnd():void{
            var _local1:String;
            this.m_stadium.playing = false;
            this.m_dialog.close();
            this.m_open.stop();
            this.m_close.stop();
            this.m_open.removeEventListener(TimerEvent.TIMER, this.onOpen);
            this.m_close.removeEventListener(TimerEvent.TIMER, this.onClose);
            if (this.m_result.result == "tie"){
                _local1 = "It was a tie!";
            } else {
                _local1 = (this.m_result.winner.name + " team won!");
            };
            _local1 = (_local1 + ((("\n\nFinal Score: " + this.m_result.winnerScore) + " - ") + this.m_result.loserScore));
            UI.displayMessage(_local1);
        }

    }
}//package Classes.sim 
